package com.maxus.mini.ecard.open.api.icontroller;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.maxus.mini.common.Constants;
import com.maxus.mini.ecard.open.api.controller.BaseController;

/**
 * 文件controller
 * 
 * @author wujinsong
 *
 */
@RestController()
@RequestMapping(value = "api/v1.0/pic")
public class PicCntroller extends BaseController {
	/**
	 * 上传附件
	 * 
	 * @param req
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "display")
	@ResponseBody()
	public void display(String picUrl,HttpServletRequest request,HttpServletResponse response) throws Exception {
        FileInputStream fis = null;  
        OutputStream os = null;  
        try {  
            fis = new FileInputStream(Constants.ROOT_RES_DIR+picUrl);  
            os = response.getOutputStream();  
            int count = 0;  
            byte[] buffer = new byte[1024 * 8];  
            while ((count = fis.read(buffer)) != -1) {  
                os.write(buffer, 0, count);  
                os.flush();  
            }  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        try {  
            fis.close();  
            os.close();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
	}
}
